<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	/* http://localhost:8080/logistics/  */
%>
<!DOCTYPE HTML>
<html>
<head>
<!-- 设置当前页面基础路径 -->
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
</head>
<body>
<article class="page-container">
	<form id="adminForm" class="form form-horizontal" method="post" action="${empty user ?'admin/insert.do':'admin/update.do'}" >
	<%--隐藏域，用户id--%>
	<input type="hidden" name="userId" value="${user.userId}">
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员账号：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<%--修改的话肯定是带着user过来的，这样就修改，没有就代表是新增--%>
			<%--修改数据回显--%>
			<input type="text" class="input-text" ${empty user ? '':'disabled'}   value="${user.username}" placeholder="请输入账号" id="username" name="username">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>真实名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${user.realname}" placeholder="请输入真实姓名" id="realname" name="realname">
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="password" class="input-text" autocomplete="off"  placeholder="确认新密码" id="password2" name="password2">
		</div>
	</div>

	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">角色：</label>
		<div class="formControls col-xs-8 col-sm-9"> 
		<span class="select-box" style="width:150px;">
			<select class="select" name="roleId" size="1">
				<option value="0">请选择</option>
				<!-- 把后台传过来的角色list展示出来 -->
				<!-- 如果是修改，先匹配角色 -->
				<c:forEach items="${roles}" var="role">
					<option ${role.roleId eq user.roleId ? 'selected':''} value="${role.roleId}">${role.rolename}</option>
				</c:forEach>
			</select>
			</span> 
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去--> 
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript">
$(function(){
	
	/* 
		开始使用Jquery.validate 表单校验插件进行表单校验
		
	*/
	
	$("#adminForm").validate({
		//校验规则
		//详细校验方法在
		// webapp\lib\jquery.validation\1.14.0\validate-methods.js
		//里面
		rules:{
			//username规则
			username:{
				required:true,//必须填写，不能为空
				rangelength:[3,10],
				//远程校验，把信息发送到服务器进行校验（ajax）
				remote: {
				    url: "admin/checkUsername.do",//后台校验地址
					//后台必须返回true/false,不能返回其他
				    type: "post",               //post方式提交
				    dataType: "json",           //接受数据格式   
				    data: {                     //要传递的数据
				        //这里的username与后台的数据绑定一致，不能乱写
				    	username: function() {
				    		//拿到username的值，传到后台
				            return $("#username").val();
				        }
				    }
				}
			},
			//realname规则
			realname:{
				required:true,
				isChinese:true,//校验是否为中文
				minlength:2
			},
			password:"required",
			password2:{
				required:true,
				equalTo:"#password"//确认密码必须和密码相同
			},
			roleId:{
				min:1
			}			
		},
		/* 校验失败的提示消息 */
		messages:{
			//和上面的校验规则一一对应
			username:{
				required:"账号不能为空",
				rangelength:"账号必须3-10之间",
				remote:"账号已经存在"
			},
			realname:{
				required:"真实名称不能为空",
				isChinese:"真实名称必须是中文",
				minlength:"最少两个汉字"
			},
			password:"密码不能为空",
			password2:{
				required:"确认密码不能为空",
				equalTo:"确认密码必须和密码相同"
			},
			roleId:{
				min:"必须选择一个角色"
			}
			
		},
		//校验成功回调函数，调用ajax进行提交
		submitHandler:function(form){
			//ajax提交数据
			//form ： 表单的js对象，先转为jq对象
			$(form).ajaxSubmit(function(data){
				//显示服务器回来的消息
				layer.msg(data.msg, {icon: data.ret,time:2000},function(){
					//如果服务器返回成功，刷新父页面
					if(data.ret == true){
						parent.refreshTable();
						parent.layer.closeAll();
					}
					
				});
			})
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>